package com.xcity.game.combat.skill.impl;

import java.util.List;

import com.xcity.game.combat.Action;
import com.xcity.game.combat.ActionEffect;
import com.xcity.game.combat.CombatUtils;
import com.xcity.game.combat.skill.CombatSkill;
import com.xcity.game.combat.unit.CombatUnit;
import com.xcity.game.common.GameStaticConfig;
import com.xcity.game.skill.Skill;

/**
 * 饥饿营销<br/>
 * are your ok？do you like mi？雷布斯使用饥饿营销战术攻击全体敌方目标{0}次，每次造成雷布斯{1}%技能伤害
 * @author yang.li
 *
 */
public class COMBAT_SKILL_90113 extends CombatSkill {

	public COMBAT_SKILL_90113(Skill skill) {
		super(skill);
	}

	@Override
	public void calcDamage(Action action) {
		CombatUnit source = action.unit;
		float rate = skill.getParameter(1) / GameStaticConfig.percentBase;
		int count = (int) skill.getParameter(0);
		List<CombatUnit> targets = action.target.all();
		for (int c = 0; c < count; c++) { // 每个目标攻击count次
			Action act = null;
			for (int i = 0; i < targets.size(); i++) {
				CombatUnit target = targets.get(i);
				if (!target.isDied()) {
					if (act == null) {
						act = newAction(action, source);
					}
					ActionEffect eff = act.addTarget(target);
					CombatUtils.calcMagicAttack(eff, rate);
				}
			}
		}
	}
	
	private static Action newAction(Action base, CombatUnit source) {
		if (base.getEffects() == null || base.getEffects().isEmpty()) {
			return base;
		}
		Action action = new Action(source);
		base.ref().add(action);
		return action;
	}
	
}
